package 题目集.贪心.区间贪心;

import java.util.PriorityQueue;
import java.util.Scanner;

public class ch02_区间覆盖 {
	static int s, t;
	static int n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		s = sc.nextInt();
		t = sc.nextInt();

		n = sc.nextInt();
		PriorityQueue<int[]> left = new PriorityQueue<>((a, b) -> a[0] - b[0]);
		PriorityQueue<int[]> right = new PriorityQueue<>((a, b) -> b[1] - a[1]);
		for (int i = 0; i < n; i++) {
			int[] info = { sc.nextInt(), sc.nextInt() };
			left.add(info);
		}
		int cur = s;
		int cnt=0;
		do {
			while(!left.isEmpty()&&left.peek()[0]<=cur) {
				right.add(left.poll());
			}
			if(right.isEmpty()) {
				cnt=-1;
				break;
			}else {
				cnt++;
				cur=right.poll()[1];
			}
		}while(cur<t);
		System.out.println(cnt);
	}
}
